<?php

namespace lxs\aliyun;
use App\Exceptions\WrongException;


class SendSms
{
    private array $templateCode = [
        'login_code' => 'SMS_465432214', // 登录注册验证码
    ];


    /**
     * 发送短信
     * @param $phoneNumber
     * @param $data = ['code' => 1234]; // 模板中的变量
     * @param $template
     * @return string|void
     */
    public function send($phoneNumber, $data, $template){
        //短信模板Code
        $templateCode = $this->templateCode[$template] ?? '';
        if (!$templateCode) {
            return '模板有误';
        }
        $aliSms = new \Mrgoon\AliSms\AliSms();
        $response = $aliSms->sendSms($phoneNumber,$templateCode, $data);
        if($response->Message == 'OK'){//发送成功
            return true;
        }else {//发送失败
            return false;
            //throw new WrongException('发送验证码失败');
        }
    }

}
